%{
// Copyright 2007 Arnoud de Vries
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
%}

%{
#include "service.h"
#include "parser.cpp.h"
%}

%Start init literal comment htmlcomment

White0          [ \t\r\f\v]
White           {White0}|\n

CommentStart    \#\*
CommentEnd      \*\#

HtmlCommentStart    <!--
HtmlCommentEnd      -->

Hint            {White0}*[A-Z0-9_]+{White0}*:.*\n   

OperatorOrWhite    [ \t\r\f\v\n\(\)\\\+\-\*\/\%]

%%

<init>#if                { return KWIF;}
<init>#else              { return KWELSE;}
<init>#elseif            { return KWELSE;}
<init>#foreach           { return KWFOR;}
<init>#each              { return KWEACH; }
<init>#before            { return KWBEFORE; }
<init>#after             { return KWAFTER; }
<init>#between           { return KWBETWEEN; }
<init>#odd               { return KWODD; }
<init>#even              { return KWEVEN; }
<init>#nodata            { return KWNODATA; }
<init>#beforeall         { return KWBEFOREALL; }
<init>#afterall          { return KWAFTERALL; }
<init>#set               { return KWSET;}
<init>#end               { return KWEND;}
<init>#stop              { return KWSTOP;}
<init>#macro             { return KWMACRO; } 
<init>#literal           { return KWLITERAL; }
<init>#capturefor        { return KWCAPTUREFOR; }
<init>#blockcomponent    { return KWBLOCKCOMPONENT; } 
<init>#component         { return KWCOMPONENT; };

<init>#include           { return KWINCLUDE; } 
<init>{White}in          { return KWIN; } 
<init>#parse             { return KWPARSE; } 

<init>$!?[a-zA-Z][a-zA-Z0-9_.-]*           { return IDENTIFIER; }
<init>$!?\{[a-zA-Z][a-zA-Z0-9_.-]*\}       { return IDENTIFIER; }

<init>[0-9]+                    { return NUMBER; }

<init>\"[^"]*\"                 { return STRING; }
<init>'[^']*'                   { return STRING; }

<init>##.*\n                    { return LINE_COMMENT; }

<init>,                         { return ',';    }
<init>\(                        { return '(';    }
<init>\)                        { return ')';    }
<init>\{                        { return '{';    }
<init>\}                        { return '}';    }
<init>==                        { return '=';    }

<init>\^                        { return '^';    }
<init>\+                        { return '+';    }
<init>\-                        { return '-';    }
<init>\*                        { return '*';    }
<init>\/                        { return '/';    }
<init>\!                        { return '!';    }
<init>=                         { return EQ;  }
<init>\!=                       { return NEQ;   }
<init>\>                        { return GT; }
<init>\>=                       { return GTE;    }
<init>\<                        { return LT;     }
<init>\<=                       { return LTE;    }
<init>\&                        { return '&';    }
<init>\&\&                      { return AMPAMP; }
<init>\|                        { return '|';    }
<init>\|\|                      { return BARBAR; }
<init>\.                        { return '.';    }
<init>\[                        { return '[';    }
<init>\]                        { return ']';    }

<init>{CommentStart}            { g_service->enterComment( comment );
                                  yymore();
                                } 
                                
<init>{HtmlCommentStart}        { g_service->enterComment(htmlcomment);yymore();}                        
<htmlcomment>{HtmlCommentEnd}   { g_service->leaveComment();return LEX_COMMENT;}
                                
<init>{White0}+                 { return LEX_WHITE; }
<init>\n                        { return LEX_WHITE; }
<init>.                         { /*char buf[80];
                                  sprintf_s( buf, 80, "invalid character ('%c', 0x%x)", yytext[0], yytext[0] );
                                  g_service->lexicalError( SevError, buf );*/
                                  yymore();
                                }

<comment>{CommentStart}         { g_service->enterComment();
                                  yymore();
                                }
<comment,htmlcomment>{CommentEnd}           { g_service->leaveComment();
                                  return LEX_COMMENT;
                                }
<comment,htmlcomment>.         { yymore(); }
<comment,htmlcomment>\n        { return LEX_COMMENT; }

.|\n                            { g_service->setLexState(init); yyless(0); }


%%

#include <stdservice.c>